<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>苞米面 C++ 模板库: bmm/algo.hpp 源文件</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">苞米面 C++ 模板库
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- 制作者 Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'搜索');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','搜索');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_3855b158c164314995fac6a2abe3aa9c.html">bmm</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">algo.hpp</div>  </div>
</div><!--header-->
<div class="contents">
<a href="algo_8hpp.html">浏览该文件的文档.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160; </div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="preprocessor">#ifndef _BMM_ALGO_HPP_</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="preprocessor">#define _BMM_ALGO_HPP_</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160; </div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="preprocessor">#include &lt;algorithm&gt;</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="preprocessor">#include &quot;<a class="code" href="global_8hpp.html">global.hpp</a>&quot;</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160; </div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;_BMM_NAMESPACE_BEGIN_</div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160; </div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> _ArrayT, <span class="keyword">typename</span> _T&gt;</div>
<div class="line"><a name="l00025"></a><span class="lineno"><a class="line" href="algo_8hpp.html#a45259df1de3782dc9b23879e147bcf07">   25</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="algo_8hpp.html#a45259df1de3782dc9b23879e147bcf07">is_in</a>(<span class="keyword">const</span> _ArrayT &amp;__arr, <span class="keyword">const</span> _T &amp;__val)</div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;{</div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;    <span class="keywordflow">return</span> std::find(__arr.begin(), __arr.end(), __val) != __arr.end();</div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;}</div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160; </div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="keyword">template</span> &lt;<span class="keyword">typename</span> _ArrayT, <span class="keyword">typename</span> _T, <span class="keyword">typename</span> _Func = std::function&lt;<span class="keywordtype">void</span>(_T &amp;)&gt;&gt;</div>
<div class="line"><a name="l00040"></a><span class="lineno"><a class="line" href="algo_8hpp.html#a02e2995ba708b32f13e2550bac8e912a">   40</a></span>&#160;<span class="keywordtype">bool</span> <a class="code" href="algo_8hpp.html#a02e2995ba708b32f13e2550bac8e912a">if_in</a>(_ArrayT &amp;__arr, <span class="keyword">const</span> _T &amp;__val, _Func __func)</div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;{</div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;    <span class="keyword">auto</span> __it = std::find(__arr.begin(), __arr.end(), __val);</div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;    <span class="keywordflow">if</span> (__it != __arr.end())</div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;    {</div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;        __func(*__it);</div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;        <span class="keywordflow">return</span> <span class="keyword">true</span>;</div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;    }</div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;    <span class="keywordflow">return</span> <span class="keyword">false</span>;</div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;}</div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160; </div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;_BMM_NAMESPACE_END_</div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160; </div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="preprocessor">#endif // _BMM_ALGO_HPP_</span></div>
</div><!-- fragment --></div><!-- contents -->
<div class="ttc" id="aalgo_8hpp_html_a02e2995ba708b32f13e2550bac8e912a"><div class="ttname"><a href="algo_8hpp.html#a02e2995ba708b32f13e2550bac8e912a">if_in</a></div><div class="ttdeci">bool if_in(_ArrayT &amp;__arr, const _T &amp;__val, _Func __func)</div><div class="ttdoc">如果找到第一个符合条件的值，则调用函数 __func 并返回 true，否则返回 false</div><div class="ttdef"><b>Definition:</b> algo.hpp:40</div></div>
<div class="ttc" id="aglobal_8hpp_html"><div class="ttname"><a href="global_8hpp.html">global.hpp</a></div><div class="ttdoc">全局设置</div></div>
<div class="ttc" id="aalgo_8hpp_html_a45259df1de3782dc9b23879e147bcf07"><div class="ttname"><a href="algo_8hpp.html#a45259df1de3782dc9b23879e147bcf07">is_in</a></div><div class="ttdeci">bool is_in(const _ArrayT &amp;__arr, const _T &amp;__val)</div><div class="ttdoc">判断 value 是否在容器中</div><div class="ttdef"><b>Definition:</b> algo.hpp:25</div></div>
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
制作者 &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>
